﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace GuildWars2PositionManaged2
{
    //struct LinkedMem {
    //    uint32_t uiVersion;
    //    uint32_t uiTick;
    //    float	fAvatarPosition[3];
    //    float	fAvatarFront[3];
    //    float	fAvatarTop[3];
    //    wchar_t	name[256];
    //    float	fCameraPosition[3];
    //    float	fCameraFront[3];
    //    float	fCameraTop[3];
    //    wchar_t	identity[256];
    //    uint32_t context_len;
    //    unsigned char context[256];
    //    wchar_t description[2048];
    //};

    //struct MumbleContext {
    //    byte serverAddress[28]; // contains sockaddr_in or sockaddr_in6
    //    unsigned mapId;
    //    unsigned mapType;
    //    unsigned shardId;
    //    unsigned instance;
    //    unsigned buildId;
    //};

    [StructLayout(LayoutKind.Sequential, Pack = 1)]
    public struct LinkContext
    {
        [MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.U1, SizeConst = 28)]
        public byte[] ServerAddress;

        [MarshalAs(UnmanagedType.U4)]
        public UInt32 MapId;

        [MarshalAs(UnmanagedType.U4)]
        public UInt32 MapType;

        [MarshalAs(UnmanagedType.U4)]
        public UInt32 ShardId;

        [MarshalAs(UnmanagedType.U4)]
        public UInt32 Instance;

        [MarshalAs(UnmanagedType.U4)]
        public UInt32 BuildId;
    }

    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
    public struct LinkData
    {
        [MarshalAs(UnmanagedType.U4)]
        public UInt32 Version;

        [MarshalAs(UnmanagedType.U4)]
        public UInt32 Tick;

        [MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.R4, SizeConst = 3)]
        public float[] AvatarPosition;

        [MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.R4, SizeConst = 3)]
        public float[] AvatarFront;

        [MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.R4, SizeConst = 3)]
        public float[] AvatarTop;

        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
        public string Name;

        [MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.R4, SizeConst = 3)]
        public float[] CameraPosition;

        [MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.R4, SizeConst = 3)]
        public float[] CameraFront;

        [MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.R4, SizeConst = 3)]
        public float[] CameraTop;

        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
        public string Identity;

        [MarshalAs(UnmanagedType.U4)]
        public UInt32 ContextLen;

        // Context
        [MarshalAs(UnmanagedType.Struct)]
        public LinkContext Context;
        /*
        [MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.U4, SizeConst = 7)]
        public UInt32[] ServerAddress;

        [MarshalAs(UnmanagedType.U4)]
        public UInt32 MapId;

        [MarshalAs(UnmanagedType.U4)]
        public UInt32 MapType;

        [MarshalAs(UnmanagedType.U4)]
        public UInt32 ShardId;

        [MarshalAs(UnmanagedType.U4)]
        public UInt32 Instance;

        [MarshalAs(UnmanagedType.U4)]
        public UInt32 BuildId;*/
    }
}
